//
//  AsNewMsgCell.m
//  AttendenceSys
//
//  Created by 窦芳俊 on 16/6/6.
//  Copyright © 2016年 窦芳俊. All rights reserved.
//

#import "AsNewMsgCell.h"

@implementation AsNewMsgCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self initCell];
    }
    return self;
}

- (void)initCell
{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIView* bgView = [[UIView alloc] initWithFrame:CGRectMake(0,
                                                              0,
                                                              [UIScreen mainScreen].bounds.size.width,
                                                              AsNewMsgCellHeight)];
    bgView.backgroundColor = [UIColor whiteColor];
    
    _appBegEndTimeLab = [[UILabel alloc] initWithFrame:CGRectMake(15,
                                                                  10,
                                                                  [UIScreen mainScreen].bounds.size.width * 3 / 4,
                                                                  20)];
    [_appBegEndTimeLab setBackgroundColor:[UIColor clearColor]];
    _appBegEndTimeLab.font = [UIFont systemFontOfSize:15];
    [_appBegEndTimeLab setTextAlignment:NSTextAlignmentLeft];
    _appBegEndTimeLab.textColor = [UIColor blackColor];
    [bgView addSubview:_appBegEndTimeLab];
    
    _appInfoLab = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-25-40-30,
                                                            _appBegEndTimeLab.frame.origin.y,
                                                            80,
                                                            _appBegEndTimeLab.frame.size.height)];
    [_appInfoLab setBackgroundColor:[UIColor clearColor]];
    _appInfoLab.font = [UIFont systemFontOfSize:15];
    [_appInfoLab setTextAlignment:NSTextAlignmentRight];
    _appInfoLab.textColor = RGB(166, 166, 166);
    [bgView addSubview:_appInfoLab];
    
    _appTimeLab = [[UILabel alloc] initWithFrame:CGRectMake(_appBegEndTimeLab.frame.origin.x,
                                                            _appBegEndTimeLab.frame.origin.y + _appBegEndTimeLab.frame.size.height + 5,
                                                            _appBegEndTimeLab.frame.size.width,
                                                            20)];
    [_appTimeLab setBackgroundColor:[UIColor clearColor]];
    _appTimeLab.font = [UIFont systemFontOfSize:15];
    [_appTimeLab setTextAlignment:NSTextAlignmentLeft];
    _appTimeLab.textColor = RGB(166, 166, 166);
    [bgView addSubview:_appTimeLab];
    
    // 请假描述
    _msgDesc = [[UILabel alloc] initWithFrame:CGRectMake(_appTimeLab.frame.origin.x,
                                                         _appTimeLab.frame.origin.y + _appTimeLab.frame.size.height,
                                                         _appTimeLab.frame.size.width,
                                                         20)];
    _msgDesc.backgroundColor = [UIColor clearColor];
    _msgDesc.font = [UIFont systemFontOfSize:15];
    [_msgDesc setTextAlignment:NSTextAlignmentLeft];
    _msgDesc.textColor = RGB(166, 166, 166);
    [bgView addSubview:_msgDesc];
    
    //销假
    _reviewBtn = [[UIButton alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-35-40,
                                                            AsNewMsgCellHeight-38,
                                                            70,
                                                            28)];
    _reviewBtn.hidden = YES;
    [_reviewBtn setTitle:@"同意" forState:UIControlStateNormal];
    [_reviewBtn addTarget:self action:@selector(clickReviewBtn:) forControlEvents:UIControlEventTouchUpInside];
    [_reviewBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _reviewBtn.backgroundColor = RGB(252, 119, 62);
    [bgView addSubview:_reviewBtn];
    
    [self.contentView addSubview:bgView];
    
    // bottom line
    CGFloat padding = 17;
    CGFloat bgWidth = [[UIScreen mainScreen] bounds].size.width;
    UIImageView* bottomLineView = [[UIImageView alloc] initWithFrame:CGRectMake(padding,
                                                                                AsNewMsgCellHeight - 1,
                                                                                bgWidth - padding * 2,
                                                                                1)];
    [bottomLineView setBackgroundColor:RGB(221, 221, 221)];
    [self.contentView addSubview:bottomLineView];
}

//销假
-(void)clickReviewBtn:(id)sender
{
    //UIButton* btn = (UIButton*)sender;
    if (_delegate && [_delegate respondsToSelector:@selector(reviewBtnClick:)])
    {
        [_delegate reviewBtnClick:(UITableViewCell *)self];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

- (void)resetCellStatus
{
    _reviewBtn.hidden = YES;
    _reviewBtn.enabled = YES;
    [_reviewBtn setTitle:@"同意" forState:UIControlStateNormal];
    [_reviewBtn addTarget:self action:@selector(clickReviewBtn:) forControlEvents:UIControlEventTouchUpInside];
    [_reviewBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _reviewBtn.backgroundColor = RGB(252, 119, 62);
}

@end



